<?php include SYSDIR_VIEW ."/common/header.html";?>

<script type="text/javascript" src="<?php echo SYSDIR_HUIADMIN;?>/lib/icheck/jquery.icheck.min.js"></script> 
<script type="text/javascript" src="<?php echo SYSDIR_HUIADMIN;?>/lib/jquery.validation/1.14.0/jquery.validate.min.js"></script> 
<script type="text/javascript" src="<?php echo SYSDIR_HUIADMIN;?>/lib/jquery.validation/1.14.0/validate-methods.js"></script> 
<script type="text/javascript" src="<?php echo SYSDIR_HUIADMIN;?>/lib/jquery.validation/1.14.0/messages_zh.min.js"></script> 
<script src="http://malsup.github.io/jquery.form.js" type="text/javascript"></script>

<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 系统管理 <span class="c-gray en">&gt;</span> 基本设置 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<article class="page-container">
    <form class="text-c" method="get" action="/admin/manager/auty_edit.php">
        管理员：<span class="select-box inline">
            <select class="select" name="admin_id"> 
                <option value="">选择</option>
                <?php foreach ($admins as $key=>$val) {
                    $sed = $val['admin_id'] == $_GET['admin_id'] ? 'selected="selected"' : '';
                    echo '<option '. $sed .' value="'. $val['admin_id'] .'">'. $val['admin_user_name'] .'('. $val['admin_real_name'] .')</option>';
                };?>
            </select>
        </span>
		<button name="" id="" class="btn btn-success" type="submit"> 确定</button>
    </form>
    <form action="/admin/manager/auty_edit.php" method="post" class="form form-horizontal" id="form-admin-role-add">
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3">角色名称：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <?php if ($admin) {?>
                <?php echo $admin['admin_user_name'] .'('. $admin['admin_real_name'] .')';?>
                <?php }else{?>
                <span class="c-red">请先选择管理员，在进行权限编辑！！</span>
                <?php }?>
                <input type="hidden" value="<?php echo $admin['admin_id'];?>" id="admin_id" name="admin_id">
                <input type="hidden" value="edit" id="action" name="action">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3">权限设置：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <?php
                    $i = 0;
                    foreach ($menus as $key=>$val) {
                ?>
                <dl class="permission-list">
                    <dt>
                        <label>
                            <input type="checkbox" id="user-Character-<?php echo $i;?>">
                            <?php echo $key;?></label>
                    </dt>
                    <dd>
                        <?php
                            foreach ($val as $k=>$v) {
                        ?>
                        <dl class="cl permission-list2">
                            <dt>
                                <label class="">
                                    <input type="checkbox" <?php echo hasPower($admin['admin_id'], $v['menu_id'],1) && hasPower($admin['admin_id'], $v['menu_id'],2) ? 'checked="checked"' : '';?> id="user-Character-<?php echo $i;?>-0">
                                    <?php echo $v['menu_name'];?><span style="color:#ddd;">&nbsp;&nbsp;|</span></label>
                            </dt>
                            <dd>
                                <label class="">
                                    <input type="checkbox" value="<?php echo $v['menu_id'];?>_1" <?php echo hasPower($admin['admin_id'], $v['menu_id'],1) ? 'checked="checked"' : '';?> name="pers[]" id="user-Character-<?php echo $i;?>-0-0">
                                    查看</label>
                                <label class="">
                                    <input type="checkbox" value="<?php echo $v['menu_id'];?>_2" <?php echo hasPower($admin['admin_id'], $v['menu_id'],2) ? 'checked="checked"' : '';?> name="pers[]" id="user-Character-<?php echo $i;?>-0-1">
                                    编辑</label>
                            </dd>
                        </dl>
                        <?php
                        }
                        ?>
                    </dd>
                </dl>
                <?php
                    $i++;
                }
                ?>
            </div>
        </div>
        <div class="row cl">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                <button type="submit" class="btn btn-success radius" id="admin-role-save"><i class="icon-ok"></i> 确定</button>
            </div>
        </div>
    </form>
</article>

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript">
$(function(){
    $(".permission-list dt input:checkbox").click(function(){
        $(this).closest("dl").find("dd input:checkbox").prop("checked",$(this).prop("checked"));
    });
    $(".permission-list2 dd input:checkbox").click(function(){
        var l =$(this).parent().parent().find("input:checked").length;
        var l2=$(this).parents(".permission-list").find(".permission-list2 dd").find("input:checked").length;
        if($(this).prop("checked")){
            $(this).closest("dl").find("dt input:checkbox").prop("checked",true);
            $(this).parents(".permission-list").find("dt").first().find("input:checkbox").prop("checked",true);
        }
        else{
            if(l==0){
                $(this).closest("dl").find("dt input:checkbox").prop("checked",false);
            }
            if(l2==0){
                $(this).parents(".permission-list").find("dt").first().find("input:checkbox").prop("checked",false);
            }
        }
    });
    
    $("#form-admin-role-add").validate({
        rules:{
            admin_id:{
                required:true,
            },
        },
        onkeyup:false,
        focusCleanup:true,
        success:"valid",
        submitHandler:function(form){

            $(form).ajaxSubmit({
                type: 'post', // 提交方式 get/post
                url: '/admin/manager/auty_edit.php', // 需要提交的 url
                data: {
                    //'title': 'y',
                },
                success: function(data) { // data 保存提交后返回的数据，一般为 json 数据
                    // 此处可对 data 作相关处理
                    if (data == 0) {
                        alert('操作成功');
                    }
                    else {
                        alert('操作失败');
                    }
                }
            });

        }
    });
});
</script>

<?php include SYSDIR_VIEW ."/common/footer.html";?>
